﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using Ccit.OA.Utils;

namespace Ccit.OA.NewsCenter
{
    public partial class news_comments_management : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hdNewsId.Value = (null != Request.QueryString["Id"]) ? Request.QueryString["Id"].ToString() : "";
                lblTitleName.Text = SysInterface.GetNameStrByIdStr("NEWS_A3", "NEWS_A3_10", "NEWS_A3_30", hdNewsId.Value, "");
                /* 评论类型：Manage：管理； */
                hdCommentType.Value = (null != Request.QueryString["Pur"]) ? Request.QueryString["Pur"].ToString() : "";
                InitPage();
            }
        }

        private void InitPage()
        {
            string sCommentType = hdCommentType.Value;
            if (sCommentType != "Manage")
            {
                tdContent.Style["display"] = "none";
                tdContent1.Style["display"] = "none";

                haCancelTop.Style["display"] = "none";
                haCancelTop1.Style["display"] = "none";
                haDelete.Style["display"] = "none";
                haDelete1.Style["display"] = "none";
                haSearch.Style["display"] = "none";
                haSearch1.Style["display"] = "none";
                haTop.Style["display"] = "none";
                haTop1.Style["display"] = "none";
                trComment.Style["display"] = "block";
            }
        }

        [global::System.Web.Services.WebMethod]
        public static string GetCommentByClause(string sNewsId,string sCommentContent,string sSortType,int iCurrPageNo,int iEveryPageRecordNum)
        {
            string sResult = "";
            CommentBLL oComment = new CommentBLL();
            List<MsComment> lstComment = oComment.GetCommentByClause(sNewsId, sCommentContent, sSortType);
            int iExpresCount = lstComment.Count;
            if (iExpresCount > 0)
            {
                int iPageCount = (iExpresCount % iEveryPageRecordNum == 0) ? iExpresCount / iEveryPageRecordNum : iExpresCount / iEveryPageRecordNum + 1;
                iPageCount = (iPageCount == 0) ? 1 : iPageCount;
                List<MsComment> lstReturnComment = new List<MsComment>();
                if (iCurrPageNo < iPageCount)
                {
                    //reg: i=(5-1)*20;i<5*20;i++
                    for (int i = (iCurrPageNo - 1) * iEveryPageRecordNum; i < iCurrPageNo * iEveryPageRecordNum; i++)
                    {
                        MsComment msComment = lstComment[i];
                        msComment.CommentContent = msComment.CommentContent.Replace("\r\n","<br />");
                        lstReturnComment.Add(msComment);
                    }
                }
                else
                {
                    //reg:i=(7-1)*20;i<135;i++
                    for (int i = (iCurrPageNo - 1) * iEveryPageRecordNum; i < iExpresCount; i++)
                    {
                        MsComment msComment = lstComment[i];
                        msComment.CommentContent = msComment.CommentContent.Replace("\r\n", "<br />");
                        lstReturnComment.Add(msComment);
                    }
                }
                string sReturnComment = JavaScriptConvert.SerializeObject(lstReturnComment);
                var oResult = new { CommentResult = sReturnComment, CommentCount = iExpresCount, PageCount = iPageCount };
                sResult = JavaScriptConvert.SerializeObject(oResult);
            }
            return sResult;
        }

        [global::System.Web.Services.WebMethod]
        public static string OperateComment(string sCommentIds, string sOperType)
        {
            string sResult = "";
            CommentBLL oComment = new CommentBLL();
            bool bFlag = oComment.OperateComment(sCommentIds, sOperType);            
            var oResult = new { OperType = sOperType, ExeResult = bFlag };
            sResult = JavaScriptConvert.SerializeObject(oResult);
            return sResult;
        }
    }
}
